<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class model_login extends CI_Model
{
    public function __construct() {
        parent::__construct();
    }

    public function check($user, $pass) {

      	$this->db->select('mahocsinh');
        $this->db->from('hocsinh');
        $this->db->where('mahocsinh', $user);
        $this->db->where('matkhau', $pass);

      	$query = $this->db->get();

      	if ($query->num_rows() == 1) {
            return 1;
      	} else {
            $this->db->select('maphuhuynh');
            $this->db->from('phuhuynh');
            $this->db->where('maphuhuynh', $user);
            $this->db->where('matkhau', $pass);

            $query = $this->db->get();

            if ($query->num_rows() == 1) {
                return 2;
            } else {
                $this->db->select('magiaovien, machucvu');
                $this->db->from('giaovien');
                $this->db->where('magiaovien', $user);
                $this->db->where('matkhau', $pass);

                $query = $this->db->get();

                if ($query->num_rows() == 1) {
                    return 3;
                } else {
                    return 0;
                }
            }
      	}
    }

}